﻿using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.WebAPI.Application.Command.SheepCommand;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.SheepCommandHandler
{
    public class SheepUpdateCommandHandler : IRequestHandler<SheepUpdateCommand, Results<int>>
    {

        private readonly ISheepService sheepService;
        private readonly ILogger<SheepUpdateCommandHandler> logger;
        public SheepUpdateCommandHandler(ISheepService sheepService, ILogger<SheepUpdateCommandHandler> logger)
        {
            this.sheepService = sheepService;
            this.logger = logger;
        }


        /// <summary>
        /// 羊场修改
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<int>> Handle(SheepUpdateCommand request, CancellationToken cancellationToken)
        {
            var entity = new Sheepfactory()
            {
                Address = request.Address,
                DepartId = request.DepartId,
                EstablishingTime = DateTime.Now,
                Isdelete = 0,
                ResponsiblePerson = request.ResponsiblePerson,
                SheepAbbreviation = request.SheepAbbreviation,
                SheepAddr = request.SheepAddr,
                SheepFullName = request.SheepFullName,
                SheepId = request.SheepId,
                SheepNumber = request.SheepNumber,
                SheepScale = request.SheepScale,
                State = request.State,

            };

            var list = await sheepService.Update(entity);

            return Results<int>.DataResult(list);
        }






    }






}
